<template>
    <div class="main">
        <div style="width: 100%;height: 40px;background-color: #fff;margin-bottom: 20px;padding: 10px;">当前模块:<span
                style="font-weight: bold;">设置本校区开设的教学课程(各年级开班的学科) </span> </div>
        <div class="main-body">

            <div class="main-header float-left">

                <el-form :inline="true" :model="formInline" class="demo-form-inline" size="mini">

                    <el-form-item label="筛选条件：">
                        <el-select v-model="formInline.xq" placeholder="请选择">
                            <el-option v-for="item in ddl_lb_list" :key="item" :label="item" :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="">
                        <el-select v-model="formInline.nj" placeholder="请选择" clearable>
                            <el-option v-for="(item, index) in ddl_bb_list" :key="index" :label="item.mc"
                                :value="item.dm">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
                        <el-button type="primary" icon="el-icon-plus" @click="addCourse">新增课程</el-button>
                        <el-button type="primary" icon="el-icon-delete" @click="rowdeletes"
                            :disabled="multipleSelection.length <= 0">批量删除</el-button>
                    </el-form-item>
                </el-form>
                <!-- </div> -->
            </div>

            <el-dialog title="课程(学科)设置详细信息显示与操作窗口" :visible.sync="dialogDetails" width="40%">
                <div>

                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="160px" class="demo-ruleForm">

                        <el-form-item label="选择开设课程的年级:" prop="nj" @change="njchange">
                            <el-select v-model="ruleForm.nj" placeholder="请选择">
                                <el-option v-for="(item, index) in ddl_bb_list" :key="index" :label="item.mc"
                                    :value="item.dm">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="课程的教学组织方式:" prop="jxzzfs" @change="jxzzfschange">
                            <el-select v-model="ruleForm.jxzzfs" placeholder="请选择">
                                <el-option v-for="(item, index) in jxzzfslist" :key="index" :label="item.MC"
                                    :value="item.DM">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="选择开设课程的性质:" prop="kcxz" @change="kcxzchange">
                            <el-select v-model="ruleForm.kcxz" placeholder="请选择">
                                <el-option v-for="(item, index) in kcxzlist" :key="index" :label="item.MC"
                                    :value="item.DM">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <!-- 下拉多选框 -->
                        <el-form-item label="选择开设的课程" prop="type">
                            <el-dropdown>
                                <span class="el-dropdown-link">下拉选择
                                    <i class="el-icon-arrow-down el-icon--right"></i>
                                </span>
                                <el-dropdown-menu slot="dropdown">
                            <el-checkbox-group v-model="ruleForm.type">
                                <el-checkbox v-for="(item, index) in radioList" :key="index" :label="item.DM" name="type">{{ item.mc }}</el-checkbox>
                            </el-checkbox-group>
                            <el-button type="primary" @click="confirmSelection" style="text-align: center;">确认选择</el-button>
                            <button @click="showCheckboxes = false">取消</button> 
                        </el-dropdown-menu>
                    </el-dropdown>
                        </el-form-item>
                        <!-- <el-form-item label="选择开设的课程" prop="type">
                            <el-select  v-model="ruleForm.type" placeholder="请选择">
                           <el-option  v-for="(item, index) in radioList" :key="index" :label="item.DM" name="type">
                                <el-checkbox>{{ item.mc }}</el-checkbox>
                           </el-option>
                        </el-select>
                        </el-form-item> -->
                        <el-form-item>
                            <el-button type="primary" @click="submitForm('ruleForm')">提 交</el-button>
                            <el-button @click="dialogDetails = false">取 消</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <!-- <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogDetails = false">取 消</el-button>
                    <el-button type="primary" @click="dialogDetails = false">提 交</el-button>
                </span> -->
            </el-dialog>

            <div class="main-center float-left">
                <el-table :data="tableData" height="650" style="width: 100%;margin-top: 6px;"
                    :header-cell-style="{ background: '#fafafa', color: '#000000e0', fontWeight: 600 }"
                    @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55">
                    </el-table-column>
                    <el-table-column type="index" label="序号" width="100"></el-table-column>
                    <el-table-column prop="XQ" label="学期"></el-table-column>
                    <el-table-column prop="NJMC" label="年级"></el-table-column>
                    <el-table-column prop="KCMC" label="课程名称"></el-table-column>
                    <el-table-column prop="KC_ID" label="课程代码"></el-table-column>
                    <el-table-column prop="ZBFS" label="组班方式"></el-table-column>
                    <el-table-column prop="KCXZMC" label="课程性质"></el-table-column>
                    <el-table-column prop="XM" label="操作人"></el-table-column>
                    <el-table-column prop="ztmc" label="状态"></el-table-column>
                    <el-table-column label="详情" width="100">
                        <template slot-scope="scope" style="z-index: -9999;">
                            <el-button @click="handleDelete(scope.row)" type="text" size="small" style="color: #ff4d4f;"
                                icon="el-icon-delete">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="footer-pagination">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="formInline.currentPage" :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]"
                        :page-size="formInline.limit" layout="total, sizes, prev, pager, next, jumper"
                        :total="formInline.total">
                    </el-pagination>
                </div>
            </div>

        </div>
    </div>
</template>
<script>
import httplogin from "../../api/login";

export default {
    name: 'Social',
    data() {
        return {
            showCheckboxes: false,
            ruleForm: {
                nj: '',
                jxzzfs: '',
                kcxz: "",
                type: [],// 下拉框多选框选中的内容

            },
            jxzzfslist: [],
            multipleSelection: [],
            rules: {
                nj: [
                    { required: true, message: '请选择开设课程的年级', trigger: 'change' }
                ],
                jxzzfs: [
                    { required: true, message: '请选择课程的教学组织方式', trigger: 'change' }
                ],
                kcxz: [
                    { required: true, message: '请选择开设课程的性质', trigger: 'change' }
                ],
                type: [
                    { type: 'array', required: true, message: '请至少选择一个开设的课程', trigger: 'change' }
                ],

            },
            printOption: {
                id: 'nbprint', // 打印元素的id 不需要携带#号
                popTitle: '教职工基本信息登记表' // 页眉标题 默认浏览器标题 空字符串时显示undefined 使用html语言
            },
            tableData: [],
            formInline: {
                xq: "",
                nj: '',
                xm: '',
                ddl_xz: '',
                ddl_jdfs: '',
                currentPage: 1,
                limit: 10,
                total: 0
            },
            ddl_lb_list: [

            ],//类别 options
            ddl_bb_list: [],//办别 options
            ddl_xz_list: [
                {
                    value: '全部',
                    label: '全部'
                },
                {
                    value: '普通',
                    label: '普通'
                },
                {
                    value: '工读',
                    label: '工读'
                },
                {
                    value: '特教',
                    label: '特教'
                },
            ],//性质 options
            ddl_jdfs_list: [
                {
                    value: '全部',
                    label: '全部'
                },
                {
                    value: '走读',
                    label: '走读'
                },
                {
                    value: '寄宿',
                    label: '寄宿'
                },
            ],//就读方式 options
            dialogDetails: false,
            JiaoZhiGongInfo: {},
            schoolList: [],
            radioList: []

        }
    },
    mounted() {
       
        this.getSemesterway();
      
    },
    methods: {
    // 下拉多选框点击确认
    confirmSelection() {
    // 处理选中的选项
    console.log("选中的选项:", this.ruleForm.type);
      // 关闭下拉框
    this.$refs.dropdown.hide();
    },
        njchange() {
            this.getIsNotSetSubjectway()
        },
        jxzzfschange() {
            this.getIsNotSetSubjectway()
        },
        kcxzchange() {
            this.getIsNotSetSubjectway()
        },
        handleDelete(row) {
            var arrId = []
            arrId.push(row.ID)
            var data = {
                ids:arrId
            }
            this.$confirm('此操作将删除记录, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                httplogin.delSubject(data).then(res => {
                    if (res.data.code == 200) {
                        this.$message.success(res.data.msg, 3);

                        this.getSubjectway()
                    }
                })
            }).catch(() => {

            });

        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    var data = {
                        jxzzfs: this.ruleForm.jxzzfs,
                        nj: this.ruleForm.nj,
                        kcxz: this.ruleForm.kcxz,
                        xq: this.formInline.xq,
                        newXqdm: localStorage.getItem("selXQDM"),
                        kcIds: this.ruleForm.type
                    }
                    httplogin.saveSubject(data).then(res => {
                        if (res.data.code == 200) {
                            this.$message.success(res.data.msg, 3);
                            this.dialogDetails = false
                            this.getSubjectway()
                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        async getSubjectway() {
            let data = {
                xq: this.formInline.xq,
                page: this.formInline.currentPage,
                size: this.formInline.limit,
                benqu: this.formInline.benqu,
                nj: this.formInline.nj,
            }
            let res = await httplogin.getSubject(data);
            if (res.data.code == 200) {
                this.tableData = res.data.data.list,
                    this.formInline.total = res.data.data.total
            }
        },
        async getSemesterway() {
            let res = await httplogin.getSemester();
            if (res.data.code == 200) {
                this.ddl_lb_list = res.data.data.list
                this.formInline.xq = this.ddl_lb_list[0]
                this.getGradeway()
            }
        },
        async getGradeway() {
            let res = await httplogin.getGrade();
            if (res.data.code == 200) {
                this.ddl_bb_list = res.data.data.list
                this.getSubjectway()
            }
        },
        //getGrade

        getNowTimeDate() {
            const now = new Date();
            const year = now.getFullYear();
            const month = ('0' + (now.getMonth() + 1)).slice(-2);
            const day = ('0' + now.getDate()).slice(-2);
            // const hours = ('0' + now.getHours()).slice(-2);
            // const minutes = ('0' + now.getMinutes()).slice(-2);
            // const seconds = ('0' + now.getSeconds()).slice(-2);
            const formattedTime = year + "年" + month + "月" + day + "日"
            return formattedTime
        },
        sortPingyinfun(list) {
            list.sort((a, b) => a.XQJC.localeCompare(b.XQJC))
            return list
        },
        //点击查看详情 open 弹框
        handleClick(row) {
            this.getOnGuardFacultyInfoway(row)
            this.dialogDetails = true
        },
        async getOnGuardFacultyInfoway(val) {
            var data = {
                jzgId: val.TeacherID
            }
            var res = await httplogin.getOnGuardFacultyInfo(data)
            if (res.data.code == 200) {
                this.JiaoZhiGongInfo = res.data.data.jzgInfo

            }
        },
        addCourse() {
            this.ruleForm.nj = this.ddl_bb_list[0].dm
            this.getAllDistListway()
            this.dialogDetails = true
        },
        async getAllDistListway() {
            var res = await httplogin.getAllDistList();
            if (res.data.code == 200) {
                this.jxzzfslist = res.data.data.data.dm_jw_jxzzfs
                this.kcxzlist = res.data.data.data.dm_jw_kcxz
                this.ruleForm.jxzzfs = this.jxzzfslist[0].DM
                this.ruleForm.kcxz = this.kcxzlist[0].DM
                this.getIsNotSetSubjectway()
            }
        },
        async getIsNotSetSubjectway() {
            var data = {
                xq: this.formInline.xq,
                nj: this.ruleForm.nj,
                kcxz: this.ruleForm.kcxz,
                jxzzfs: this.ruleForm.jxzzfs,
                gzXqdm: localStorage.getItem("selXQDM")
            }
            var res = await httplogin.getIsNotSetSubject(data);
            if (res.data.code == 200) {
                this.radioList = res.data.data.list
            }
        },
        //close 弹框
        handleClose() {
            this.dialogDetails = false
        },
        onSubmit() {
            this.getSubjectway()
            // console.log(this.formInline);
        },
        handleSizeChange(val) {
            this.formInline.limit = val
            this.getSubjectway()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.formInline.currentPage = val
            this.getSubjectway()
            console.log(`当前页: ${val}`);
        },
        handleSelectionChange(val) {
            this.multipleSelection=[]
            for (let i = 0; i < val.length; i++) {
                this.multipleSelection.push(val[i].ID)
            }

        },
        rowdeletes() {
            var data = {
                ids: this.multipleSelection
            }
            this.$confirm('此操作将删除记录, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                httplogin.delSubject(data).then(res => {
                    if (res.data.code == 200) {
                        this.multipleSelection=[]
                        this.$message.success(res.data.msg, 3);

                        this.getSubjectway()
                    }
                })
            }).catch(() => {

            });
        },
    }
}
</script>

<style scoped>
.main {
    width: 100%;
    float: left;
    height: auto;
    box-sizing: border-box;
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #f6f6f6;
    overflow-x: auto;
    overflow-y: auto;
}

.main-body {
    width: 100%;
    height: auto;
    float: left;
    background-color: #fff;
    box-sizing: border-box;
    padding: 18px;
    border-radius: 12px;
}

.float-left {
    width: 100%;
    height: auto;
    float: left;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.d-flex {
    display: flex;
    align-items: center;
}

.mr-24 {
    margin-right: 24px;
}

.fontcolor {
    color: rgba(0, 0, 0, 0.88);
    word-break: break-word;
    line-height: 1.5714285714285714;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    font-size: 14px;
    box-sizing: border-box;
}

.footer-pagination {
    padding: 10px 0 0 0;
    text-align: right;
}

.font-all {
    color: rgba(0, 0, 0, 0.88);
    font-size: 14px;
    line-height: 1.5714285714285714;
    list-style: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
    scrollbar-color: rgba(0, 0, 0, 0.25) rgba(5, 5, 5, 0.06);
}
</style>

<style scoped>
::v-deep .el-dialog {
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow: auto;
}

::v-deep .el-dialog__header {
    background-color: #ff4d4f !important;

}

::v-deep .el-dialog__title {
    line-height: 24px;
    font-size: 20px;
    color: #fff !important;
    /* font-weight: 600; */
}
</style>